package com.avic.rong.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.activity.mine.GrabageCollectActivity;
import com.avic.rong.bean.mine.HelpCenterBean;
import com.umeng.commonsdk.debug.E;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;

public class HelpCenterAdapter extends RecyclerView.Adapter {

    //标题  网址
    public ArrayList<HelpCenterBean.ChannelListBean.ContentBean> mList;

    private Context context;


    private int TYPE_TITLE = 1000;
    private int TYPE_CONTENT = 1001;

    private int position;

    private String channelName;

    public void setChannelName(String channelName) {
        this.channelName = channelName;
    }

    public HelpCenterAdapter(ArrayList<HelpCenterBean.ChannelListBean.ContentBean> mList, Context context) {
        this.mList = mList;
        this.context = context;
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.item_helpcenter, viewGroup, false);
        return new HelpCenterHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, int i) {
        HelpCenterHolder helpCenterHolder = (HelpCenterHolder) viewHolder;
        int itemViewType = getItemViewType(i);
        if (itemViewType == TYPE_TITLE){
            helpCenterHolder.ivRight.setVisibility(View.INVISIBLE);
            helpCenterHolder.tvTitle.setText(channelName);
        }else if (itemViewType == TYPE_CONTENT){
            position = i-1;
            HelpCenterBean.ChannelListBean.ContentBean contentBean = mList.get(position);
            helpCenterHolder.ivRight.setVisibility(View.VISIBLE);
            helpCenterHolder.tvTitle.setText(contentBean.getTitle());

            helpCenterHolder.rlRoot.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    context.startActivity(GrabageCollectActivity.queryIntent(context,contentBean.getTitle(),contentBean.getSubheadTitle()));
                }
            });
        }

    }

    @Override
    public int getItemCount() {
        return mList.size()+1;
    }

    @Override
    public int getItemViewType(int position) {
        if (position == 0){
            return TYPE_TITLE;
        }else {
            return TYPE_CONTENT;
        }
    }

    public class HelpCenterHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_title)
        TextView tvTitle;
        @BindView(R.id.rl_root)
        RelativeLayout rlRoot;
        @BindView(R.id.img_right)
        ImageView ivRight;
        public HelpCenterHolder(@NonNull View itemView) {
            super(itemView);
            ButterKnife.bind(this,itemView);
        }
    }

}
